package com.tian.service.impl.manage;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.tian.mapper.ReportMapperCustom;
import com.tian.pojo.Report;
import com.tian.pojo.bo.ReportBO;
import com.tian.pojo.vo.ReportManageVO;
import com.tian.pojo.vo.ReportVO;
import com.tian.pojo.vo.UserManageVO;
import com.tian.service.ReportService;
import com.tian.service.UserService;
import com.tian.service.manage.ReportManageService;
import com.tian.utils.PagedGridResult;
import org.n3r.idworker.Sid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;

@Service
public class ReportManageServiceImpl implements ReportManageService {



    @Autowired
    private ReportMapperCustom reportMapperCustom;






    @Transactional(propagation = Propagation.SUPPORTS)
    @Override
    public PagedGridResult queryPagedReport(Integer page, Integer pageSize) {


            PageHelper.startPage(page,pageSize);
            List<ReportManageVO> list = reportMapperCustom.queryPagedReportManage();

            for (ReportManageVO l:list){
                Integer handlestatus = l.getHandlestatus();
                Integer reporttype = l.getReporttype();
                if (handlestatus==1){
                    l.setHandlestatusStr("已处理");
                }else {
                    l.setHandlestatusStr("未处理");
                }

                if (reporttype==1){
                    l.setReporttypeStr("假冒与盗版");
                }
                if (reporttype==2){
                    l.setReporttypeStr("虚假交易");
                }
                if (reporttype==3){
                    l.setReporttypeStr("收到空包裹");
                }
                if (reporttype==4){
                    l.setReporttypeStr("滥发信息");
                }


            }

            return setterPagedGrid(list,page);

    }
    @Transactional
    @Override
    public int deleteReport(String id) {
        int i = reportMapperCustom.deleteReport(id);
        return i;
    }

    @Transactional
    @Override
    public int handleReportManage(String id) {
        int handlestatus = reportMapperCustom.queryhandlestatusById(id);
        if (handlestatus==0){
            handlestatus=1;
        }
        Map<String,Object> map =new HashMap<>();
        map.put("handlestatus",handlestatus);
        map.put("id",id);

        int i = reportMapperCustom.handleReportManage(map);
        return i;
    }

    @Transactional(propagation = Propagation.SUPPORTS)
    @Override
    public List<ReportManageVO> getReportManageByUserName(String username) {

        List<ReportManageVO> list = reportMapperCustom.getReportManageByUserName(username);

        return list;

    }

    private PagedGridResult setterPagedGrid(List<?> list,Integer page){
        PageInfo<?> pageList =new PageInfo<>(list);
        PagedGridResult grid=new PagedGridResult();
        grid.setPage(page);
        grid.setRows(list);
        grid.setTotal(pageList.getPages());
        grid.setRecords(pageList.getTotal());
        return grid;
    }
}
